package com.tech.java;

/**
 * @Description:
 * @Author: zl
 * @Date: 2019/9/11 16:48
 */
public class StringReserve {

    //java api 的实现
    public static String reverse01(String str) {
        return new StringBuilder(str).reverse().toString();
    }

    // 转成数组 -- 数组下标是从0- 数组长度-1
    public static String reverse02(String str) {
        String rStr = "";
        char[] chars = str.toCharArray();
        for (int i = chars.length - 1; i >= 0; i--) {
            rStr += chars[i];
        }
        return rStr;
    }

    // 字符串
    public static String  reverse03(String str){
        String string = "";
        for (int i=0;i<str.length();i++) {
            string = str.charAt(i) + string;
        }
        return  string;

    }


    public static void main(String[] args) {
        String string = "abcdefg";
        System.out.println(reverse01(string));
        System.out.println(reverse02(string));
        System.out.println(reverse03(string));
    }
}
